<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax</title>
</head>
<body>
<div class="box">
    <button class="btn" onclick="getMssage()">登录</button>
    <div class="message"></div>
</div>
<script>
    function getMssage(){
        var xhr = new XMLHttpRequest();
        xhr.open("get","/hello?username='zhangsan'",true);
        xhr.send();
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status == 200){
                //var data = JSON.parse(xhr.responseText);
                console.log(xhr);
                console.log(xhr.response);
                var el=document.querySelector(".message");
                el.innerHTML=xhr.response;
                //alert("登录成功");
                /*if(data.code == 200){
                    console.log(xhr);
                    alert("登录成功");
                }else{
                    alert("登录失败");
                }*/
            }
        }
    }
</script>
</body>
</html>